package com.wsj.a.collapsingdemo.utils;

import android.databinding.DataBindingUtil;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.Toast;

import com.wsj.a.collapsingdemo.App;

import com.wsj.a.collapsingdemo.R;
import com.wsj.a.collapsingdemo.databinding.LayoutCustomToastBinding;


/**
 * created by linxiujie
 *TODO:提示工具
 */
public class ToastUtil {
    private static ToastUtil mInstance;
    private Toast mToast;
    private LayoutCustomToastBinding mBinding;

    public  static ToastUtil getInstance(){
        if (mInstance == null) {
            synchronized (ToastUtil.class) {
                if (mInstance == null) {
                    mInstance = new ToastUtil();
                }
            }
        }
        return mInstance;
    }



    public void show(String message){

        if(mToast==null){
            mToast=new Toast(App.getInstance());
            mToast.setGravity(Gravity.CENTER,0,0);
            mToast.setDuration(Toast.LENGTH_SHORT);
            mBinding= DataBindingUtil.inflate(LayoutInflater.from(App.getInstance()), R.layout.layout_custom_toast,null,false);
            mToast.setView(mBinding.getRoot());
        }
        mBinding.toast.setText(message);
        mToast.show();
    }

    public  void show(int res){
        show(App.getInstance().getResources().getString(res));
    }




}
